package com.zy.bootdemo.controller;

import com.zy.bootdemo.entity.UserEntity;
import com.zy.bootdemo.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Service
@RestController
public class UserController {
    @Resource
    UserService userService;
    @PostMapping("/login")
    public boolean login(UserEntity userEntity, HttpSession session){

        return userService.login(userEntity,session);
    }
    @PostMapping("/user/updatePwd")
    public boolean updatePwd(String oldPassword,String newPassword,String rePassword,HttpSession session) {
        boolean flag = userService.updatePwd(oldPassword, newPassword, rePassword, (UserEntity) session.getAttribute("curUser"));
        if (flag) {
            session.invalidate();
        }
        return flag;
    }
}
